package org.luu.medicare.controller.commonController;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.luu.medicare.common.Result;
import org.luu.medicare.entity.PageBean;
import org.luu.medicare.entity.Person;
import org.luu.medicare.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/person")
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
@Slf4j
public class PersonController {
    private final PersonService personService;

    @DeleteMapping("/{id}")
    public Result<String> deleteById(@PathVariable Integer id) {
        log.info("个人 deleteById: {}", id);
        return personService.deleteById(id);
    }

    @GetMapping("/{id}")
    public Result<Person> findById(@PathVariable Integer id) {
        log.info("个人 findById: {}", id);
        return personService.findById(id);
    }

    @GetMapping()
    public Result<PageBean<Person>> page(@RequestParam(defaultValue = "1") int page,
                                          @RequestParam(defaultValue = "10") int pageSize,
                                          String name,
                                          String id) {
        log.info("个人 page: {}, {}, {}, {}", page, pageSize, name, id);
        return personService.page(page, pageSize, name, id);
    }

    @PostMapping
    public Result<String> save(@RequestBody Person person) {
        log.info("个人 save: {}", person);
        return personService.save(person);
    }

    @PutMapping
    public Result<String> update(@RequestBody Person person) {
        log.info("个人 update: {}", person);
        return personService.update(person);
    }
}
